/**
 * 
 */
package com.oolong.account.web;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.oolong.account.model.UserModel;
import com.oolong.account.service.StaticManage;
import com.oolong.account.vo.DateStaticVo;

/**
 * @author oolong
 * 
 */
// 标记它是个SPRING的BEAN，是MVC里的C
@Controller
// 表示这个类就是staticdayOutItem.do
@RequestMapping("/staticdaybtwOutItem.do")
public class StaticDaybtwController {
	Logger logger = Logger.getLogger(StaticDaybtwController.class);
	// 表示需要SPRING自动注入
	@Autowired
	private StaticManage staticManage;
	String message;

	@RequestMapping(method = RequestMethod.POST)
	public String processOutItem(@RequestParam("startday") String startday,
			@RequestParam("endday") String endday, ModelMap model,
			HttpServletResponse response, HttpSession session) {
		UserModel userModel = (UserModel) session.getAttribute("user");
		int user_id = userModel.getId();
		String pattern = "yyyy-MM-dd";
		SimpleDateFormat simpledf = new SimpleDateFormat(pattern);
		List<DateStaticVo> dateStaticVos;
		response.setContentType("text/html;charset=UTF-8");
		try {
			dateStaticVos = staticManage.DayBtwStaticService(user_id,
					simpledf.parse(startday), simpledf.parse(endday));
			model.addAttribute("dateStaticVos", dateStaticVos);
			String time = startday + "到" + endday;
			model.addAttribute("time", time);
			return "staticoutday";
		} catch (ParseException e) {
			message = "日期格式不正确";
			model.addAttribute("message", message);
			return "deleteOutItem";
		}
	}

	@RequestMapping(method = RequestMethod.GET)
	public String processOutItem(ModelMap model, HttpServletResponse response,
			HttpSession session) {
		UserModel userModel = (UserModel) session.getAttribute("user");
		int user_id = userModel.getId();
		response.setContentType("text/html;charset=UTF-8");
		return "querybtwout";
	}
}
